package com.easy.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.easy.common.bean.UserBean;
import com.easy.common.util.MonthGrowthVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<UserBean> {
    @Select("""
    SELECT 
        year,
        month,
        count,
        CONCAT(year, '-', LPAD(month, 2, '0')) as yearMonth
    FROM (
        SELECT 
            YEAR(createtime) as year,
            MONTH(createtime) as month,
            COUNT(*) as count
        FROM user 
        GROUP BY YEAR(createtime), MONTH(createtime)
    ) temp
    ORDER BY year, month
    """)
    List<MonthGrowthVO> countUserGrowthByMonth();

}
